

package control;

import interfaces.*;
import java.util.*;
import plantObjects.*;

/**
 * Dispatching-System. Creates Plan and identifies how many slabs are needed
 * to be transportet from/to where
 * @author iii
 */
public class Plan {

    // Lists with Position for the different operations to be done
    private ArrayList<Position> barsFromStartStorage = new ArrayList<Position>();
    private ArrayList<Position> barsFromEndStorage = new ArrayList<Position>();
    private ArrayList<Position> barsToEndStorage = new ArrayList<Position>();
    private int barsToWaggon;

    /**
     * Creates new Plan for a given Order
     * @param Order order
     */
    public Plan(Order order)
    {
        String barType = order.getBarType();
        barsToWaggon = order.getNumOfBars();

        // determines the Position of available Bars in EndStorage
        barsFromEndStorage = storageDB.getShortBars(barType, barsToWaggon);

        // determines how many Bars are needed from Saw
        int numBarsFromSaw = barsToWaggon - barsFromStartStorage.size();
        // determines # Bars to be put in EndStorage
        int numBarsToEndStor = -numBarsFromSaw % 3;
        // determine # Bars needed from StartStorage
        int numBarsFromStartStor = (numBarsFromSaw + numBarsToEndStor)/3;

        // determines the Position of Bars in StartStorage
        barsFromEndStorage = storageDB.getLongBars(barType, numBarsFromStartStor);
        // determines free Positions in EndStorage
        barsToEndStorage = storageDB.addShortBars(barType, numBarsToEndStor);
        
    }


    
    /**
     * @return the barsFromStartStorage
     */
    public ArrayList<Position> getBarsFromStartStorage() {
        return barsFromStartStorage;
    }

    /**
     * @return the barsFromEndStorage
     */
    public ArrayList<Position> getBarsFromEndStorage() {
        return barsFromEndStorage;
    }

    /**
     * @return the barsToEndStorage
     */
    public ArrayList<Position> getBarsToEndStorage() {
        return barsToEndStorage;
    }

    /**
     * @return the barsToWaggon
     */
    public int getBarsToWaggon() {
        return barsToWaggon;
    }

}
